package com.ruoyi.web.controller.djb;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.djb.domain.DjbDistrictUser;
import com.ruoyi.djb.service.IDjbDistrictUserService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 住户管理Controller
 * 
 * @author xxd
 * @date 2023-12-08
 */
@Controller
@RequestMapping("/djb/districtUser")
public class DjbDistrictUserController extends BaseController
{
    private String prefix = "djb/districtUser";

    @Autowired
    private IDjbDistrictUserService djbDistrictUserService;

    @RequiresPermissions("djb:districtUser:view")
    @GetMapping()
    public String districtUser()
    {
        return prefix + "/districtUser";
    }

    /**
     * 查询住户管理列表
     */
    @RequiresPermissions("djb:districtUser:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DjbDistrictUser djbDistrictUser)
    {
        startPage();
        List<DjbDistrictUser> list = djbDistrictUserService.selectDjbDistrictUserList(djbDistrictUser);
        return getDataTable(list);
    }

    /**
     * 导出住户管理列表
     */
    @RequiresPermissions("djb:districtUser:export")
    @Log(title = "住户管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DjbDistrictUser djbDistrictUser)
    {
        List<DjbDistrictUser> list = djbDistrictUserService.selectDjbDistrictUserList(djbDistrictUser);
        ExcelUtil<DjbDistrictUser> util = new ExcelUtil<DjbDistrictUser>(DjbDistrictUser.class);
        return util.exportExcel(list, "住户管理数据");
    }

    /**
     * 新增住户管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存住户管理
     */
    @RequiresPermissions("djb:districtUser:add")
    @Log(title = "住户管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DjbDistrictUser djbDistrictUser)
    {
        return toAjax(djbDistrictUserService.insertDjbDistrictUser(djbDistrictUser));
    }

    /**
     * 修改住户管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        DjbDistrictUser djbDistrictUser = djbDistrictUserService.selectDjbDistrictUserById(id);
        mmap.put("djbDistrictUser", djbDistrictUser);
        return prefix + "/edit";
    }

    /**
     * 修改保存住户管理
     */
    @RequiresPermissions("djb:districtUser:edit")
    @Log(title = "住户管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DjbDistrictUser djbDistrictUser)
    {
        return toAjax(djbDistrictUserService.updateDjbDistrictUser(djbDistrictUser));
    }

    /**
     * 删除住户管理
     */
    @RequiresPermissions("djb:districtUser:remove")
    @Log(title = "住户管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(djbDistrictUserService.deleteDjbDistrictUserByIds(ids));
    }
}
